package com.ku.consumerpay.service.mq;

import cn.hutool.core.util.IdUtil;
import cn.hutool.json.JSONUtil;
import com.ku.consumerpay.service.mq.SyncProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: rocketMQKill
 * @description: 被PayServiceImpl所调用
 * @author: JokerKu
 * @create: 2020-05-06 23:31
 **/
@Service
public class CallBackService {
    public static final String CALLBACK_PAY_TOPIC = "callback_pay_topic";

    public static final String CALLBACK_PAY_TAGS = "callback_pay";


    @Autowired
    private SyncProducer syncProducer;

    public void sendOKMessage(String orderId, String userId) {
        Map<String, Object> params = new HashMap<>();
        params.put("orderId", orderId);
        params.put("userId", userId);
        params.put("OderStatus", "2");//支付成功

        final String KEYS = IdUtil.randomUUID();

        Message message = new Message(CALLBACK_PAY_TOPIC, CALLBACK_PAY_TAGS, KEYS, JSONUtil.toJsonStr(params).getBytes(Charset.defaultCharset()));

        SendResult sendResult = syncProducer.sendMessage(message);
    }
}
